package com.srd.phone.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.shengrongdai.srd.R;
import com.srd.phone.bean.SucceedLoan;
import com.srd.phone.utils.views.ViewHolder;

import java.util.ArrayList;
import java.util.List;

public class SucceedLoanAdapter extends BaseAdapter {

    private Context context;
    private List<SucceedLoan> list = new ArrayList<SucceedLoan>(10);

    public SucceedLoanAdapter(Context context, List<SucceedLoan> list0) {
        this.context = context;
        list = list0;
    }

    public void setData(List<SucceedLoan> list0) {
        list = list0;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public SucceedLoan getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View view, ViewGroup parent) {
        ViewHolder viewHolder =  ViewHolder.get(context, view, parent, R.layout.item_succeed_loan, position);

        SucceedLoan item = getItem(position);
        TextView tv_name = viewHolder.getView(R.id.tv_name);
        tv_name.setText(item.nm);

        TextView tv_money = viewHolder.getView(R.id.tv_money);
        tv_money.setText(item.moneys + "元");

        TextView tv_date = viewHolder.getView(R.id.tv_date);
        tv_date.setText(item.ctime);

        TextView tv_state = viewHolder.getView(R.id.tv_state);

        switch(item.stat){
            case 56:
                tv_state.setText("还款");
                tv_state.setTextColor(context.getResources().getColor(R.color.green));
                tv_state.setBackgroundResource(R.drawable.shape_state_border_green);
                break;
            case 26:
                tv_state.setText("查看");
                tv_state.setTextColor(context.getResources().getColor(R.color.yellow));
                tv_state.setBackgroundResource(R.drawable.shape_state_border_yellow);
                break;
        }

        return viewHolder.getConvertView();
    }
}
